package com.ksd.pug.cloud.controller;

import com.ksd.pug.cloud.pojo.SysUser;
import com.ksd.pug.cloud.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 这两个注解的合成 ： Controller + ResponseBody
 */
@RestController
@Slf4j
public class UserController {

    @Autowired
    private IUserService userService;


    @GetMapping("/user/{id}")
    public SysUser findById(@PathVariable Long id) {
        System.out.println("执行查询了。。。。。。。。");
        return userService.getById(id);
    }

    @GetMapping("/user/batch")
    public List<SysUser> findByIds(String userIds) {
        String[] split = userIds.split(",");
        List<Long> collect = Arrays.stream(split).map(id -> new Long(id)).collect(Collectors.toList());
        log.info("执行查询了。。。。。。。。{}", collect);
        return userService.listByIds(collect);
    }
}
